```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MySQL锁机制详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        :root {
            --primary-color: #3b82f6;
            --secondary-color: #10b981;
            --accent-color: #8b5cf6;
            --text-primary: #1f2937;
            --text-secondary: #6b7280;
        }
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: var(--text-primary);
            line-height: 1.6;
        }
        h1, h2, h3 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero {
            background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-4px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .sql {
            background-color: #f8f9fa;
            border-left: 4px solid var(--primary-color);
        }
        .advantage {
            border-left: 4px solid var(--secondary-color);
        }
        .disadvantage {
            border-left: 4px solid #ef4444;
        }
        .table-container {
            overflow-x: auto;
        }
        table {
            min-width: 100%;
            border-collapse: separate;
            border-spacing: 0;
        }
        th {
            background-color: #f3f4f6;
        }
        td, th {
            padding: 0.75rem;
            text-align: left;
            border-bottom: 1px solid #e5e7eb;
        }
        .mermaid {
            background-color: white;
            padding: 1rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .tooltip {
            position: relative;
        }
        .tooltip-text {
            visibility: hidden;
            width: 200px;
            background-color: #333;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 5px;
            position: absolute;
            z-index: 1;
            bottom: 125%;
            left: 50%;
            transform: translateX(-50%);
            opacity: 0;
            transition: opacity 0.3s;
        }
        .tooltip:hover .tooltip-text {
            visibility: visible;
            opacity: 1;
        }
        .highlight {
            background-color: rgba(59, 130, 246, 0.1);
            padding: 0.25rem 0.5rem;
            border-radius: 0.25rem;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold text-gray-900 mb-4">MySQL锁机制深度解析</h1>
            <p class="text-xl text-gray-600 mb-8">探索数据库并发控制的核心机制与最佳实践</p>
            <div class="flex justify-center space-x-4">
                <span class="px-4 py-2 bg-blue-100 text-blue-800 rounded-full text-sm font-medium">行锁</span>
                <span class="px-4 py-2 bg-green-100 text-green-800 rounded-full text-sm font-medium">表锁</span>
                <span class="px-4 py-2 bg-purple-100 text-purple-800 rounded-full text-sm font-medium">并发控制</span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="text-lg text-gray-700 mb-6">在数据库系统中，锁机制是保证数据一致性和事务隔离性的核心技术。MySQL作为最流行的关系型数据库之一，提供了多种锁机制以适应不同的应用场景。本文将深入探讨MySQL中的行锁和表锁机制，分析它们的优缺点及适用场景。</p>
            
            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3">
                            <i class="fas fa-key text-blue-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">锁的核心作用</h3>
                    </div>
                    <p class="text-gray-600">锁机制主要用于解决并发事务中的数据一致性问题，确保在多个事务同时访问数据库时，数据能够保持正确和一致的状态。</p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-100">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center mr-3">
                            <i class="fas fa-project-diagram text-green-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">锁的权衡</h3>
                    </div>
                    <p class="text-gray-600">选择锁策略时需要在锁的开销、并发性能和数据一致性之间找到平衡点，不同的业务场景需要不同的锁策略。</p>
                </div>
            </div>

            <div class="mermaid mb-8">
                graph TD
                    A[MySQL锁机制] --> B[表级锁]
                    A --> C[行级锁]
                    A --> D[页面锁]
                    B --> E[MyISAM默认]
                    C --> F[InnoDB默认]
                    D --> G[BDB引擎]
                    B --> H[开销小,加锁快]
                    C --> I[并发度高,粒度细]
            </div>
        </section>

        <!-- Row Lock Section -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-12 h-12 rounded-lg bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-bars text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">行锁(Row Lock)</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <div class="card bg-white p-6 rounded-xl advantage">
                    <h3 class="text-xl font-semibold mb-4 text-green-700 flex items-center">
                        <i class="fas fa-check-circle mr-2"></i> 优势
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>锁的粒度小，发生锁冲突的概率低</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>处理并发的能力强</span>
                        </li>
                    </ul>
                </div>
                <div class="card bg-white p-6 rounded-xl disadvantage">
                    <h3 class="text-xl font-semibold mb-4 text-red-700 flex items-center">
                        <i class="fas fa-exclamation-circle mr-2"></i> 劣势
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>开销大</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>加锁慢</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>会出现死锁</span>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="mb-8">
                <h3 class="text-2xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-lock-open mr-3 text-blue-500"></i> 加锁方式
                </h3>
                <div class="bg-white p-6 rounded-xl shadow-sm mb-6">
                    <p class="text-gray-700 mb-4">InnoDB存储引擎自动加锁规则：</p>
                    <ul class="space-y-2 text-gray-700 mb-6">
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-blue-500 mt-1 mr-2"></i>
                            <span>对于<span class="highlight">UPDATE、DELETE和INSERT</span>语句，InnoDB会自动给涉及数据集加<span class="font-medium">排他锁</span></span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-blue-500 mt-1 mr-2"></i>
                            <span>对于普通<span class="highlight">SELECT</span>语句，InnoDB不会加任何锁</span>
                        </li>
                    </ul>
                    
                    <p class="text-gray-700 mb-4">也可以显式加锁：</p>
                    <div class="grid md:grid-cols-2 gap-4">
                        <div class="sql p-4 rounded-lg">
                            <p class="text-sm text-gray-500 mb-2">共享锁(读锁)</p>
                            <p class="font-mono text-gray-800">SELECT * FROM tableName <br>WHERE ... <span class="text-blue-600">LOCK IN SHARE MODE</span>;</p>
                        </div>
                        <div class="sql p-4 rounded-lg">
                            <p class="text-sm text-gray-500 mb-2">排他锁(写锁)</p>
                            <p class="font-mono text-gray-800">SELECT * FROM tableName <br>WHERE ... <span class="text-blue-600">FOR UPDATE</span>;</p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bg-blue-50 p-6 rounded-xl border border-blue-100">
                <div class="flex items-start">
                    <div class="flex-shrink-0 text-blue-500 mr-3 mt-1">
                        <i class="fas fa-info-circle text-xl"></i>
                    </div>
                    <div>
                        <h4 class="text-lg font-semibold text-blue-800 mb-2">关键区别</h4>
                        <p class="text-gray-700">InnoDB和MyISAM的最大不同点有两个：一，InnoDB支持事务(transaction)；二，默认采用行级锁。加锁可以保证事务的一致性，可谓是有人(锁)的地方，就有江湖(事务)。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Table Lock Section -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-12 h-12 rounded-lg bg-green-100 flex items-center justify-center mr-4">
                    <i class="fas fa-table text-green-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">表锁(Table Lock)</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6 mb-8">
                <div class="card bg-white p-6 rounded-xl advantage">
                    <h3 class="text-xl font-semibold mb-4 text-green-700 flex items-center">
                        <i class="fas fa-check-circle mr-2"></i> 优势
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>开销小</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>加锁快</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                            <span>无死锁</span>
                        </li>
                    </ul>
                </div>
                <div class="card bg-white p-6 rounded-xl disadvantage">
                    <h3 class="text-xl font-semibold mb-4 text-red-700 flex items-center">
                        <i class="fas fa-exclamation-circle mr-2"></i> 劣势
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>锁粒度大，发生锁冲突的概率高</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                            <span>并发处理能力低</span>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="mb-8">
                <h3 class="text-2xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-lock mr-3 text-green-500"></i> 加锁方式
                </h3>
                <div class="bg-white p-6 rounded-xl shadow-sm mb-6">
                    <p class="text-gray-700 mb-4">MyISAM存储引擎自动加锁规则：</p>
                    <ul class="space-y-2 text-gray-700 mb-6">
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-green-500 mt-1 mr-2"></i>
                            <span>查询操作(<span class="highlight">SELECT</span>)，会自动给涉及的所有表加<span class="font-medium">读锁</span></span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-green-500 mt-1 mr-2"></i>
                            <span>更新操作(<span class="highlight">UPDATE、DELETE、INSERT</span>)，会自动给涉及的表加<span class="font-medium">写锁</span></span>
                        </li>
                    </ul>
                    
                    <p class="text-gray-700 mb-4">也可以显式加锁：</p>
                    <div class="grid md:grid-cols-2 gap-4">
                        <div class="sql p-4 rounded-lg">
                            <p class="text-sm text-gray-500 mb-2">共享读锁</p>
                            <p class="font-mono text-gray-800"><span class="text-blue-600">LOCK TABLE</span> tableName <span class="text-blue-600">READ</span>;</p>
                        </div>
                        <div class="sql p-4 rounded-lg">
                            <p class="text-sm text-gray-500 mb-2">独占写锁</p>
                            <p class="font-mono text-gray-800"><span class="text-blue-600">LOCK TABLE</span> tableName <span class="text-blue-600">WRITE</span>;</p>
                        </div>
                    </div>
                    <div class="sql p-4 rounded-lg mt-4">
                        <p class="text-sm text-gray-500 mb-2">批量解锁</p>
                        <p class="font-mono text-gray-800"><span class="text-blue-600">UNLOCK TABLES</span>;</p>
                    </div>
                </div>
            </div>

            <div class="mb-8">
                <h3 class="text-2xl font-semibold mb-4 flex items-center">
                    <i class="fas fa-search mr-3 text-purple-500"></i> 查看加锁情况
                </h3>
                <div class="bg-white p-6 rounded-xl shadow-sm">
                    <div class="sql p-4 rounded-lg">
                        <p class="font-mono text-gray-800"><span class="text-blue-600">SHOW OPEN TABLES</span>;</p>
                    </div>
                    <p class="text-gray-700 mt-4">结果中 <span class="font-medium">1</span> 表示加锁，<span class="font-medium">0</span> 表示未加锁。</p>
                </div>
            </div>

            <div class="bg-white p-6 rounded-xl shadow-sm">
                <h3 class="text-2xl font-semibold mb-4">如何加表锁</h3>
                <p class="text-gray-700 mb-4">MyISAM在执行查询语句（SELECT）前，会自动给涉及的所有表加读锁，在执行更新操作（UPDATE、DELETE、INSERT等）前，会自动给涉及的表加写锁，这个过程并不需要用户干预，因此用户一般不需要直接用LOCK TABLE命令给MyISAM表显式加锁。</p>
                
                <p class="text-gray-700 mb-6">给MyISAM表显示加锁，一般是为了一定程度模拟事务操作，实现对某一时间点多个表的一致性读取。例如，有一个订单表orders，其中记录有订单的总金额total，同时还有一个订单明细表order_detail，其中记录有订单每一产品的金额小计subtotal，假设我们需要检查这两个表的金额合计是否相等，可能就需要执行如下两条SQL：</p>
                
                <div class="grid md:grid-cols-2 gap-6 mb-6">
                    <div class="sql p-4 rounded-lg">
                        <p class="font-mono text-gray-800"><span class="text-blue-600">SELECT</span> <span class="text-pink-600">SUM</span>(total) <span class="text-blue-600">FROM</span> orders;</p>
                    </div>
                    <div class="sql p-4 rounded-lg">
                        <p class="font-mono text-gray-800"><span class="text-blue-600">SELECT</span> <span class="text-pink-600">SUM</span>(subtotal) <span class="text-blue-600">FROM</span> order_detail;</p>
                    </div>
                </div>
                
                <p class="text-gray-700 mb-4">这时，如果不先给这两个表加锁，就可能产生错误的结果，因为第一条语句执行过程中，order_detail表可能已经发生了改变。因此，正确的方法应该是：</p>
                
                <div class="sql p-4 rounded-lg mb-6">
                    <p class="font-mono text-gray-800"><span class="text-blue-600">LOCK TABLES</span> orders <span class="text-blue-600">READ LOCAL</span>, order_detail <span class="text-blue-600">READ LOCAL</span>;</p>
                    <p class="font-mono text-gray-800 mt-2"><span class="text-blue-600">SELECT</span> <span class="text-pink-600">SUM</span>(total) <span class="text-blue-600">FROM</span> orders;</p>
                    <p class="font-mono text-gray-800 mt-2"><span class="text-blue-600">SELECT</span> <span class="text-pink-600">SUM</span>(subtotal) <span class="text-blue-600">FROM</span> order_detail;</p>
                    <p class="font-mono text-gray-800 mt-2"><span class="text-blue-600">UNLOCK TABLES</span>;</p>
                </div>
                
                <div class="bg-yellow-50 p-4 rounded-lg border border-yellow-200">
                    <h4 class="text-lg font-semibold text-yellow-800 mb-2 flex items-center">
                        <i class="fas fa-exclamation-triangle mr-2"></i> 特别说明
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <span class="text-yellow-700 mr-2">•</span>
                            <span>上面的例子在LOCK TABLES时加了'local'选项，其作用就是在满足MyISAM表并发插入条件的情况下，允许其他用户在表尾插入记录</span>
                        </li>
                        <li class="flex items-start">
                            <span class="text-yellow-700 mr-2">•</span>
                            <span>在用LOCK TABLES给表显式加表锁时，必须同时取得所有涉及表的锁，并且MySQL支持锁升级。也就是说，在执行LOCK TABLES后，只能访问显式加锁的这些表，不能访问未加锁的表；同时，如果加的是读锁，那么只能执行查询操作，而不能执行更新操作</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Comparison Section -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-12 h-12 rounded-lg bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-balance-scale text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">MySQL锁机制比较</h2>
            </div>
            
            <div class="bg-white p-6 rounded-xl shadow-sm mb-8">
                <p class="text-gray-700 mb-6">相对于其他的数据库而言，MySQL的锁机制比较简单，最显著的特点就是不同的存储引擎支持不同的锁机制。根据不同的存储引擎，MySQL中锁的特性可以大致归纳如下：</p>
                
                <div class="table-container mb-8">
                    <table class="w-full">
                        <thead>
                            <tr>
                                <th class="font-semibold text-gray-700">储存引擎</th>
                                <th class="font-semibold text-gray-700">行锁</th>
                                <th class="font-semibold text-gray-700">表锁</th>
                                <th class="font-semibold text-gray-700">页锁</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>MyISAM</td>
                                <td></td>
                                <td class="text-center">✓</td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>BDB</td>
                                <td></td>
                                <td class="text-center">✓</td>
                                <td class="text-center">✓</td>
                            </tr>
                            <tr>
                                <td>InnoDB</td>
                                <td class="text-center">✓</td>
                                <td class="text-center">✓</td>
                                <td></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="border border-gray-200 rounded-lg p-4">
                        <h4 class="text-lg font-semibold mb-3 text-blue-600 flex items-center">
                            <i class="fas fa-table mr-2"></i> 表锁
                        </h4>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-plus text-blue-500 mt-1 mr-2"></i>
                                <span>开销小，加锁快</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-plus text-blue-500 mt-1 mr-2"></i>
                                <span>不会出现死锁</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-minus text-red-500 mt-1 mr-2"></i>
                                <span>锁定力度大，发生锁冲突概率高</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-minus text-red-500 mt-1 mr-2"></i>
                                <span>并发度最低</span>
                            </li>
                        </ul>
                    </div>
                    <div class="border border-gray-200 rounded-lg p-4">
                        <h4 class="text-lg font-semibold mb-3 text-green-600 flex items-center">
                            <i class="fas fa-bars mr-2"></i> 行锁
                        </h4>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-plus text-green-500 mt-1 mr-2"></i>
                                <span>锁定粒度小，发生锁冲突的概率低</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-plus text-green-500 mt-1 mr-2"></i>
                                <span>并发度高</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-minus text-red-500 mt-1 mr-2"></i>
                                <span>开销大</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-minus text-red-500 mt-1 mr-2"></i>
                                <span>加锁慢</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-minus text-red-500 mt-1 mr-2"></i>
                                <span>会出现死锁</span>
                            </li>
                        </ul>
                    </div>
                    <div class="border border-gray-200 rounded-lg p-4">
                        <h4 class="text-lg font-semibold mb-3 text-purple-600 flex items-center">
                            <i class="fas fa-file mr-2"></i> 页锁
                        </h4>
                        <ul class="space-y-2 text-gray-700">
                            <li class="flex items-start">
                                <i class="fas fa-plus text-purple-500 mt-1 mr-2"></i>
                                <span>开销和加锁速度介于表锁和行锁之间</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-plus text-purple-500 mt-1 mr-2"></i>
                                <span>锁定粒度介于表锁和行锁之间</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-minus text-red-500 mt-1 mr-2"></i>
                                <span>会出现死锁</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-equals text-gray-500 mt-1 mr-2"></i>
                                <span>并发度一般</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="bg-gradient-to-r from-blue-50 to-purple-50 p-8 rounded-xl">
            <div class="flex items-center mb-6">
                <div class="w-12 h-12 rounded-lg bg-white flex items-center justify-center mr-4 shadow-sm">
                    <i class="fas fa-lightbulb text-yellow-500 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">总结与建议</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 text-blue-600">选择锁策略的考量因素</h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-3 flex-shrink-0">1</span>
                            <span>应用场景的并发需求程度</span>
                        </li>
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-3 flex-shrink-0">2</span>
                            <span>数据访问模式(读多写少或读少写多)</span>
                        </li>
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-3 flex-shrink-0">3</span>
                            <span>系统资源限制(CPU、内存等)</span>
                        </li>
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-blue-100 text-blue-600 flex items-center justify-center mr-3 flex-shrink-0">4</span>
                            <span>事务的复杂度和持续时间</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-sm">
                    <h3 class="text-xl font-semibold mb-4 text-green-600">最佳实践建议</h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-green-100 text-green-600 flex items-center justify-center mr-3 flex-shrink-0">1</span>
                            <span>读多写少场景考虑使用MyISAM(表锁)</span>
                        </li>
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-green-100 text-green-600 flex items-center justify-center mr-3 flex-shrink-0">2</span>
                            <span>高并发写场景优先选择InnoDB(行锁)</span>
                        </li>
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-green-100 text-green-600 flex items-center justify-center mr-3 flex-shrink-0">3</span>
                            <span>避免长时间持有锁，减少锁的粒度</span>
                        </li>
                        <li class="flex items-start">
                            <span class="w-6 h-6 rounded-full bg-green-100 text-green-600 flex items-center justify-center mr-3 flex-shrink-0">4</span>
                            <span>合理设计索引以减少锁的冲突</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    </main>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
        
        // 添加微交互效果
        document.addEventListener('DOMContentLoaded', function() {
            // 代码块复制功能
            const codeBlocks = document.querySelectorAll('.sql');
            codeBlocks.forEach(block => {
                block.addEventListener('click', function() {
                    const range = document.createRange();
                    range.selectNode(this);
                    window.getSelection().removeAllRanges();
                    window.getSelection().addRange(range);
                    document.execCommand('copy');
                    window.getSelection().removeAllRanges();
                    
                    // 显示复制成功的提示
                    const tooltip = document.createElement('div');
                    tooltip.className = 'absolute top-0 right-0 bg-green-500 text-white px-2 py-1 rounded text-xs';
                    tooltip.textContent = '已复制!';
                    this.style.position = 'relative';
                    this.appendChild(tooltip);
                    
                    setTimeout(() => {
                        tooltip.remove();
                    }, 1000);
                });
            });
            
            // 平滑滚动
            document.querySelectorAll('a[href^="#"]').forEach(anchor => {
                anchor.addEventListener('click', function (e) {
                    e.preventDefault();
                    document.querySelector(this.getAttribute('href')).scrollIntoView({
                        behavior: 'smooth'
                    });
                });
            });
        });
    </script>
</body>
</html>
```